package ${basePackage}.application.service.${modelNameLowerCamel};

import ${basePackage}.application.dto.${modelNameLowerCamel}.CreateDTO;
import ${basePackage}.application.seek.IService;
import ${basePackage}.application.seek.ServiceAbstract;
import ${basePackage}.domain.${modelNameLowerCamel}.I${modelNameUpperCamel};
import ${basePackage}.domain.${modelNameLowerCamel}.I${modelNameUpperCamel}Repository;
import ${basePackage}.domain.${modelNameLowerCamel}.${modelNameUpperCamel}Factory;
import ${basePackage}.infrastructure.${modelNameLowerCamel}.${modelNameUpperCamel}Repository;

/**
 * Created by ${author} on ${date}.
 * 描述: 创建${modelName}的业务对象
 */

public class CreateService extends ServiceAbstract<CreateDTO, Integer> implements IService<Integer> {

    /**
     * ${modelName}的仓储操作对象
     */
    private I${modelNameUpperCamel}Repository i${modelNameUpperCamel}Repository;

    /**
     * 有参构造，获取传入${modelName}对象
     *
     * @param createDTO ${modelName}信息
     */
    public CreateService(CreateDTO createDTO) {
        super(createDTO);
    }

    /**
     * 创建${modelName}的业务逻辑
     *
     * @return ${modelName}主键
     */
    @Override
    protected Integer process() {
        try {
            iUnitOfWork.begin();
            i${modelNameUpperCamel}Repository = new ${modelNameUpperCamel}Repository(iUnitOfWork);
            I${modelNameUpperCamel} i${modelNameUpperCamel} = ${modelNameUpperCamel}Factory.create${modelNameUpperCamel}(s.getName());
            Integer id = i${modelNameUpperCamel}Repository.save(i${modelNameUpperCamel});
            iUnitOfWork.commit();
            return id;
        } finally {
            iUnitOfWork.close();
        }
    }
}
